package servlet;

import util.*;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;
import java.util.Date;



public class DeleteByNum extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {



        String id=request.getParameter("id").trim();//取得用户名参数

        try{
            DButil dButil = new DButil();
            Connection con = dButil.getConnection();

            String sql = "DELETE from staff where id='" + id + "'";

            PreparedStatement ps = con.prepareStatement(sql);

            if (ps.executeUpdate() != 0){
                RequestDispatcher dispatcher =
                        request.getRequestDispatcher("index.jsp");//转发
                dispatcher.forward(request, response);
            }
            else
            {
                RequestDispatcher dispatcher=
                        request.getRequestDispatcher("index.jsp");//转发
                dispatcher.forward(request,response);
            }
        }catch(Exception e){
            e.printStackTrace();

        }
        RequestDispatcher dispatcher=
                request.getRequestDispatcher("index.jsp");//转发
        dispatcher.forward(request,response);

    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
